﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArtOfTest.WebAii.Controls.HtmlControls;

namespace SM2ReportAnalysis
{
    public class ThemesActions
    {
        public static void hitNewGraphButton()
        {
            SM2Input.Tradition.ClickButtonBYID("cphPageContent_lnkCreateCluster"); 
        }

        public static void hitNextGraphTypePage()
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            IList<HtmlInputSubmit> iListSubmit = UpdatePanel1.Find.AllByAttributes<HtmlInputSubmit>();
            HtmlInputSubmit btnNext = iListSubmit[1];
            SM2Input.Tradition.ClickButton(btnNext);
        }

        public static void inputGraphName(string strGraphName)
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            IList<HtmlInputText> iListText = UpdatePanel1.Find.AllByAttributes<HtmlInputText>();
            HtmlInputText btnNameOfGraph = iListText[0];
            SM2Input.Tradition.TypeTextIntoTextFieldWithHint(btnNameOfGraph, strGraphName);
        }

        public static void SelectGraphType(string strGraphType)
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            HtmlDiv cphPageContent_Wizard1_pnlNoClusterRunning = UpdatePanel1.Find.ById<HtmlDiv>("cphPageContent_Wizard1_pnlNoClusterRunning");
            if (strGraphType.Equals("Basic"))
            {
                //Basic 
                HtmlInputRadioButton cphPageContent_Wizard1_rbBasicGraph = cphPageContent_Wizard1_pnlNoClusterRunning.Find.ById<HtmlInputRadioButton>("cphPageContent_Wizard1_rbBasicGraph");
                SM2Input.Tradition.SelectRadio(cphPageContent_Wizard1_rbBasicGraph);
            }
            else
            {
                //Advance
                HtmlInputRadioButton cphPageContent_Wizard1_rbAdvancedGraph = cphPageContent_Wizard1_pnlNoClusterRunning.Find.ById<HtmlInputRadioButton>("cphPageContent_Wizard1_rbAdvancedGraph");
                SM2Input.Tradition.SelectRadio(cphPageContent_Wizard1_rbAdvancedGraph);
            }
        }

        public static void hitNextGraphNamePage()
        {
            HtmlDiv UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            IList<HtmlInputSubmit> iListSubmit = UpdatePanel1.Find.AllByAttributes<HtmlInputSubmit>();
            HtmlInputSubmit btnNext = iListSubmit[2];
            SM2Input.Tradition.ClickButton(btnNext);
        }

        public static void hitNextSelectCategoryPage()
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            IList<HtmlInputSubmit> iListSubmit = UpdatePanel1.Find.AllByAttributes<HtmlInputSubmit>();
            HtmlInputSubmit btnNext = iListSubmit[2];
            SM2Input.Tradition.ClickButton(btnNext);
        }

        public static void hitFinish()
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            IList<HtmlInputSubmit>  iListSubmit = UpdatePanel1.Find.AllByAttributes<HtmlInputSubmit>();
            HtmlInputSubmit btnFinish = iListSubmit[2];
            SM2Input.Tradition.ClickButton(btnFinish);
        }

        public static void loadGraph(string strGraphName)
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv div_cphPageContent_pnlUpdate = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("cphPageContent_pnlUpdate");
            HtmlSelect selectlist_cphPageContent_ddlClusters = div_cphPageContent_pnlUpdate.Find.ById<HtmlSelect>("cphPageContent_ddlClusters");
            int intCountOptions = selectlist_cphPageContent_ddlClusters.Options.Count;
            for (int i = 0; i < intCountOptions; i++)
            {
                string strBeingCheckedOption = selectlist_cphPageContent_ddlClusters.Options[i].Text.Trim();
                if (strBeingCheckedOption.Equals(strGraphName))
                {
                    selectlist_cphPageContent_ddlClusters.MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                    System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_INTERVAL_MILISECOND);

                    SM2Input.Tradition.SelectItemSelectList(selectlist_cphPageContent_ddlClusters, strBeingCheckedOption);

                    selectlist_cphPageContent_ddlClusters.Options[i].MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
                    System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_INTERVAL_MILISECOND);
                    Utilities.GlobalObject.LOGGER.log("Select graph name [" + strGraphName + "]");
                    System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_INTERVAL_MILISECOND);
                    break;
                }
            }
        }
    }
}
